<template>
	<view class="add_address_page">
		
		<view class="flex_box aic bb1">
			<view class="form_title">收货姓名</view>
			<view class="item ov">
				<input type="text" class="ipt_form_1" placeholder-style="color: #999" placeholder="请填写收货人的姓名" />
			</view>
		</view>
		
		<view class="flex_box aic bb1">
			<view class="form_title">手机号</view>
			<view class="item ov">
				<input type="text" class="ipt_form_1" placeholder-style="color: #999" placeholder="请填写收货手机号码" />
			</view>
		</view>
		
		<view class="flex_box aic bb1">
			<view class="form_title">省份地区</view>
			<view class="item ov">
				<view class="ipt_form_1" v-if="addressVal" @click="showPicker = true;">{{ addressVal }}</view>
				<view class="ipt_form_1" v-else style="color: #999;" @click="showPicker = true;">点击选择</view>
			</view>
			<image src="@/static/images/icon_arw_4.png" class="ml10 img_4"></image>
		</view>
		
		<view class="mt32 flex_box bb1">
			<view class="form_title">详细地址</view>
			<view class="item ov">
				<textarea type="text" class="textarea_form_1" placeholder-style="color: #999" placeholder="例：B座6楼602室" />
			</view>
		</view>
		
		<view class="pt32 pb32 df aic bb1">
			<view class="df aic" @click="handlesetting">
				<view class="fs0 mr10">
					<image src="@/static/images/icon_checkbox_2.png" class="img_3" mode="" v-if="isSetting"></image>
					<image src="@/static/images/icon_checkbox_1.png" class="img_3" mode="" v-else></image>
				</view>
				<view class="fs28 cor_999">设为默认地址</view>
			</view>
		</view>
		
		<view class="handle_btn_area" :class="isData ? 'isData' : ''">
			<view class="up_btn_2" v-show="isData">删除</view>
			<view class="up_btn_1">保存</view>
		</view>
		
	</view>
	<up-picker :show="showPicker" ref="uPickerRef" :columns="columns" @confirm="confirm" @cancel="showPicker = false;" @change="changeHandler"></up-picker>
</template>

<script setup>
	
	import {ref, reactive} from 'vue';
	import { onLoad, onShow, onPageScroll } from "@dcloudio/uni-app";
	
	const isSetting = ref(false);
	
	const isData = ref(true); //当有数据的时候底部操作按钮是有变化的
	
	const addressVal = ref(''); //地址
	const uPickerRef = ref(null);
	const showPicker = ref(false);
	const columns = reactive([
	  ['中国', '美国'],
	  ['深圳', '厦门', '上海', '拉萨']
	]);
	const columnData = reactive([
	  ['深圳', '厦门', '上海', '拉萨'],
	  ['得州', '华盛顿', '纽约', '阿拉斯加']
	]);
	
	const handlesetting = () => {
		isSetting.value = !isSetting.value;
	};
	
	const changeHandler = (e) => {
	  const {
	    columnIndex,
	    value,
	    values,
	    index,
	  } = e;
	
	  if (columnIndex === 0) {
	    uPickerRef.value.setColumnValues(1, columnData[index]);
	  }
	};
	
	const confirm = (e) => {
	  console.log('confirm', e);
	  addressVal.value = e.value.join('~');
	  showPicker.value = false;
	};
	
</script>

<style lang="scss" scoped>
	
	.add_address_page {
		position: relative;
		padding: 0 40rpx;
		min-height: 100vh;
		background: #fff;
		.form_title {
			position: relative;
			width: 164rpx;
			font-size: 28rpx;
			color: #333;
			text-align: left;
		}
		.ipt_form_1, .textarea_form_1 {
			position: relative;
			display: inline-block;
			width: 100%;
			height: 104rpx;
			line-height: 104rpx;
			text-align: left;
			font-size: 28rpx;
			color: #333;
			background: #fff;
			outline: none;
			border: 0;
			vertical-align: middle;
		}
		
		.textarea_form_1 {
			height: 150rpx;
			line-height: 40rpx;
		}
		
		.handle_btn_area {
			position: relative;
			margin-top: 78rpx;
			&.isData {
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			.up_btn_1 {
				position: relative;
				width: 100%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				font-size: 28rpx;
				color: #fff;
				background: #CECECE;
				border-radius: 8rpx;
			}
			.up_btn_2 {
				position: relative;
				width:308rpx;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				font-size: 28rpx;
				color: #343434;
				background: #fff;
				border: 1px solid #343434;
				border-radius: 8rpx;
			}
			&.isData .up_btn_1 { width: 308rpx; background: #F5220F; }
		}
	}

</style>
